package com.example.zhinongbao.model;

import android.os.Parcel;
import android.os.Parcelable;

public class Address implements Parcelable {
    private int id;
    private String name;
    private String phone;
    private String region;
    private String detail;
    private boolean isDefault;

    public Address(int id, String name, String phone, String region, String detail, boolean isDefault) {
        this.id = id;
        this.name = name;
        this.phone = phone;
        this.region = region;
        this.detail = detail;
        this.isDefault = isDefault;
    }

    // Parcelable要求的构造方法
    protected Address(Parcel in) {
        id = in.readInt();
        name = in.readString();
        phone = in.readString();
        region = in.readString();
        detail = in.readString();
        isDefault = in.readByte() != 0; // boolean转换
    }

    // Parcelable必需方法
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(name);
        dest.writeString(phone);
        dest.writeString(region);
        dest.writeString(detail);
        dest.writeByte((byte) (isDefault ? 1 : 0)); // boolean转换
    }

    @Override
    public int describeContents() {
        return 0; // 通常返回0
    }

    // Parcelable必需的CREATOR字段
    public static final Creator<Address> CREATOR = new Creator<Address>() {
        @Override
        public Address createFromParcel(Parcel in) {
            return new Address(in);
        }

        @Override
        public Address[] newArray(int size) {
            return new Address[size];
        }
    };

    // 原有的getter和setter方法保持不变...
    public int getId() { return id; }
    public void setId(int id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public String getPhone() { return phone; }
    public void setPhone(String phone) { this.phone = phone; }
    public String getRegion() { return region; }
    public void setRegion(String region) { this.region = region; }
    public String getDetail() { return detail; }
    public void setDetail(String detail) { this.detail = detail; }
    public boolean isDefault() { return isDefault; }
    public void setDefault(boolean isDefault) { this.isDefault = isDefault; }
    public String getFullAddress() {
        return region + " " + detail;
    }
}